import {Text, View} from '@tarojs/components'
import {CSSProperties} from 'react'

type Status = string | number

/**根据传入的数字或者字符串，返回对应的颜色 */
const getColorByStatus = (status?: Status): string => {
  let color = '#1DC79C'
  if ((status ?? undefined) === undefined) return color
  if (typeof status === 'number') {
    if (status <= 50) color = '#F86A6B'
  } else if (typeof status === 'string') {
    switch (status) {
      default:
        break
    }
  }
  return color
}

export const StatusText: React.FC<{
  status?: Status
  style?: CSSProperties
}> = ({children, status, style}): JSX.Element => {
  return (
    <View
      className="notHanzi"
      style={Object.assign(
        {
          color: getColorByStatus(status)
        },
        style
      )}
    >
      {children}
    </View>
  )
}
